package com.tancire.web.controller.company;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tancire.common.annotation.Log;
import com.tancire.common.core.controller.BaseController;
import com.tancire.common.core.domain.AjaxResult;
import com.tancire.common.enums.BusinessType;
import com.tancire.net.domain.CrmCompany;
import com.tancire.net.service.ICrmCompanyService;
import com.tancire.common.utils.poi.ExcelUtil;
import com.tancire.common.core.page.TableDataInfo;

/**
 * 客户管理Controller
 *
 * @author 陈超
 * @date 2023-12-24
 */
@RestController
@RequestMapping("/net/crmCompany")
public class CrmCompanyController extends BaseController {
    @Resource
    private ICrmCompanyService crmCompanyService;

    /**
     * 查询客户管理列表
     */
    @PreAuthorize("@ss.hasPermi('net:crmCompany:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmCompany crmCompany) {
        startPage();
        List<CrmCompany> list = crmCompanyService.selectCrmCompanyList(crmCompany);
        return getDataTable(list);
    }

    /**
     * 导出客户管理列表
     */
    @PreAuthorize("@ss.hasPermi('net:crmCompany:export')")
    @Log(title = "客户管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CrmCompany crmCompany) {
        List<CrmCompany> list = crmCompanyService.selectCrmCompanyList(crmCompany);
        ExcelUtil<CrmCompany> util = new ExcelUtil<CrmCompany>(CrmCompany.class);
        util.exportExcel(response, list, "客户管理数据");
    }

    /**
     * 获取客户管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('net:crmCompany:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(crmCompanyService.selectCrmCompanyById(id));
    }

    /**
     * 新增客户管理
     */
    @PreAuthorize("@ss.hasPermi('net:crmCompany:add')")
    @Log(title = "客户管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmCompany crmCompany) {
        return toAjax(crmCompanyService.insertCrmCompany(crmCompany));
    }

    /**
     * 修改客户管理
     */
    @PreAuthorize("@ss.hasPermi('net:crmCompany:edit')")
    @Log(title = "客户管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmCompany crmCompany) {
        return toAjax(crmCompanyService.updateCrmCompany(crmCompany));
    }

    /**
     * 删除客户管理
     */
    @PreAuthorize("@ss.hasPermi('net:crmCompany:remove')")
    @Log(title = "客户管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(crmCompanyService.deleteCrmCompanyByIds(ids));
    }

    /**
     * 重置客户密码
     */
    @PreAuthorize("@ss.hasPermi('net:crmCompany:resetPassword')")
    @GetMapping(value = "/reset/password/{id}")
    public AjaxResult resetPassword(@PathVariable("id") Long id) {
        return toAjax(crmCompanyService.resetPassword(id));
    }

    /**
     * 禁用账号
     */
    @PreAuthorize("@ss.hasPermi('net:crmCompany:disabledAccount')")
    @GetMapping(value = "/disabled/account/{id}")
    public AjaxResult disabledAccount(@PathVariable("id") Long id) {
        return toAjax(crmCompanyService.disabledAccount(id));
    }

    /**
     * 启用账号
     */
    @PreAuthorize("@ss.hasPermi('net:crmCompany:enabledAccount')")
    @GetMapping(value = "/enabled/account/{id}")
    public AjaxResult enabledAccount(@PathVariable("id") Long id) {
        return toAjax(crmCompanyService.enabledAccount(id));
    }
}
